<template>
  <div class="early-warning-statistics">
    <div class="early-warning-statistics-content">
      <div class="early-warning-statistics-content-title">预警统计</div>
      <div class="early-warning-statistics-content-tab">
        <nanning-screen-title-tab :currentTab="currentTab" @on-change-tab="onChangeTab" :tabList="tabList"></nanning-screen-title-tab>
      </div>
      <div class="early-warning-statistics-content-echarts">
        <screen-chart @initCb="initRankChart"></screen-chart>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { getRankChartOption } from './option'
import { getFaceTop } from 'api/situationAwareness/faceEarlyWarning/faceEarlyWarning'

@Component({
  name: 'early-warning-statistics'
})
export default class EarlyWarningStatisticsStatistics extends Vue {
  private rankChart: any = null

  private currentTab = 2

  private tabList: any = [
    { value: 1, label: '公司' },
    { value: 2, label: '线路' },
    { value: 3, label: '站点' },
    { value: 4, label: '车辆' }
  ]
  private data: any = []
  created() {
    this.getFaceTop()
  }

  //  tab点击
  private onChangeTab(value: any) {
    this.data = []
    this.currentTab = value
    this.getFaceTop()
  }

  //  进度条
  private initRankChart(chart: any): void {
    chart.clear()
    this.rankChart = chart
  }
  async getFaceTop() {
    const params = {
      dzcode: '',
      totalType: this.currentTab
    }
    try {
      const res: any = await getFaceTop(params)
      res.data.forEach((item: any) => {
        this.data.push({
          name: item.name,
          value: item.total
        })
      })
      setTimeout(() => {
        this.rankChart.setOption(getRankChartOption(this.data))
      }, 300)
    } catch (error) {}
  }
}
</script>

<style lang="scss" scoped>
.early-warning-statistics {
  box-sizing: border-box;
  width: 100%;
  height: calc(40% - 50px);
  .early-warning-statistics-content {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    &-title {
      width: 100%;
      height: 30px;
      line-height: 30px;
      font-size: 18px;
      font-family: 'PingFang Regular';
      font-weight: 500;
      color: #ffffff;
      position: relative;
      padding-left: 33px;
      text-align: left;
    }
    &-title::after {
      content: '';
      display: block;
      width: 10px;
      height: 10px;
      border-radius: 50%;
      background: #23fffc;
      position: absolute;
      left: 18px;
      top: 10px;
    }
    &-tab {
      box-sizing: border-box;
      width: 100%;
      height: 30px;
      padding-right: 22px;
    }
    &-echarts {
      width: 100%;
      height: calc(100% - 60px);
    }
  }
}
</style>
